void get_gwmac(pcap_t *domain, ip_address gwip, mac_address *gwmac, ip_address wlip, mac_address wlmac) {
	u_char *buf = new u_char[42];
	pcap_pkthdr *header;
	const u_char *pkt_data;
	int res;

	memset(buf, 0xff, 6);
	*(buf + 6) = wlmac.byte1;
	*(buf + 7) = wlmac.byte2;
	*(buf + 8) = wlmac.byte3;
	*(buf + 9) = wlmac.byte4;
	*(buf + 10) = wlmac.byte5;
	*(buf + 11) = wlmac.byte6;
	*(u_short *)(buf + 12) = htons(0x0806);
	*(u_short *)(buf + 14) = htons(0x0001);
	*(u_short *)(buf + 16) = htons(0x0800);
	*(buf + 18) = 6;
	*(buf + 19) = 4;
	*(u_short *)(buf + 20) = htons(0x0001);
	*(buf + 22) = wlmac.byte1;
	*(buf + 23) = wlmac.byte2;
	*(buf + 24) = wlmac.byte3;
	*(buf + 25) = wlmac.byte4;
	*(buf + 26) = wlmac.byte5;
	*(buf + 27) = wlmac.byte6;
	*(buf + 28) = wlip.byte1;
	*(buf + 29) = wlip.byte2;
	*(buf + 30) = wlip.byte3;
	*(buf + 31) = wlip.byte4;
	memset(buf + 32, 0, 6);
	*(buf + 38) = gwip.byte1;
	*(buf + 39) = gwip.byte2;
	*(buf + 40) = gwip.byte3;
	*(buf + 41) = gwip.byte4;

	pcap_sendpacket(domain, buf, sizeof(buf));

	int counter = 0;
	while (1) {
		counter ++;
		if (counter >= 1099) {
			printf("Time out. Please run again later or change a gateway.");
			exit(-1);
		}

		res = pcap_next_ex(domain, &header, &pkt_data);

		if (res > 0 && ntohs(*((u_short *)(pkt_data + 12))) == 0x0806) {
			if (*(pkt_data + 28) == gwip.byte1 && *(pkt_data + 29) == gwip.byte2 && *(pkt_data + 30) == gwip.byte3 && *(pkt_data + 31) == gwip.byte4) {
				gwmac->byte1 = *(pkt_data + 22);
				gwmac->byte2 = *(pkt_data + 23);
				gwmac->byte3 = *(pkt_data + 24);
				gwmac->byte4 = *(pkt_data + 25);
				gwmac->byte5 = *(pkt_data + 26);
				gwmac->byte6 = *(pkt_data + 27);
				delete buf;
				return;
			}
		}

		if (counter % 200 == 0) {
			printf("Retrying...\n");
			pcap_sendpacket(domain, buf, sizeof(buf));
		}
	}
}
